 //993.二又树的堂兄弟节点
 //https://leetcode.cn/problems/cousins-in-binary-tree/?envType=daily-question&envId=2024-02-08
class Solution {
public:
    bool isCousins(TreeNode* root, int x, int y) {
        if (!root) return false;
        queue<TreeNode*> q;
        q.push(root);
        while (!q.empty())
        {
            bitset<101> bs;
            int n = q.size();
            while (n--)
            {
                int cx = 0, cy = 0;
                TreeNode* node = q.front(); q.pop();
                if (node->left)
                {
                    cx = node->left->val;
                    q.push(node->left);
                }
                if (node->right)
                {
                    cy = node->right->val;
                    q.push(node->right);
                }
                //同一个父亲 则不满足
                if (cx == x && cy == y || cx == y && cy == x) continue;
                if (cx) bs.set(cx);
                if (cy) bs.set(cy);
                if (bs[x] && bs[y]) return true;
            }
        }
        return false;
    }
};